package com.gin.no_gay_alliance.viewmodel.emote;

import android.os.Parcel;
import android.os.Parcelable;

import com.gin.nga.response.emote.EmoteGroup;

import java.util.ArrayList;
import java.util.stream.Collectors;

/**
 * 表情分组
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/8/27 21:53
 **/
public class EmoteGroupModel implements Parcelable {
    public static final Creator<EmoteGroupModel> CREATOR = new Creator<EmoteGroupModel>() {
        @Override
        public EmoteGroupModel createFromParcel(Parcel in) {
            return new EmoteGroupModel(in);
        }

        @Override
        public EmoteGroupModel[] newArray(int size) {
            return new EmoteGroupModel[size];
        }
    };
    public String name;
    public ArrayList<EmoteModel> emotes;
    /**
     * 作者
     */
    public String author;
    /**
     * 版本号(如果该组来自独立来源)
     */
    public String version;
    /**
     * 来源地址(如果该组来自独立来源)
     */
    public String source;

    public EmoteGroupModel(String name, ArrayList<EmoteModel> emotes) {
        this.name = name;
        this.emotes = emotes;
    }

    public EmoteGroupModel(EmoteGroup group) {
        this.name = group.getName();
        this.emotes = group.getEmotes().stream().map(EmoteModel::new).collect(Collectors.toCollection(ArrayList::new));
    }

    public EmoteGroupModel(ThirdPartyEmoteGroup group) {
        this.name = group.name;
        this.emotes = group.data.stream().map(EmoteModel::new).collect(Collectors.toCollection(ArrayList::new));
        this.author = group.author;
        this.version = group.version;
        this.source = group.source;
    }

    protected EmoteGroupModel(Parcel in) {
        name = in.readString();
        emotes = in.createTypedArrayList(EmoteModel.CREATOR);
        author = in.readString();
        version = in.readString();
        source = in.readString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeTypedList(emotes);
        dest.writeString(author);
        dest.writeString(version);
        dest.writeString(source);
    }
}
